module.exports = (app) => {
  const { INTEGER, DATE, STRING } = app.Sequelize
  const Product = app.model.define('product', {
    id: {
      type: INTEGER(20).UNSIGNED,
      primaryKey: true,
      autoIncrement: true,
      comment: '主键id'
    },
    title: {
      type: STRING(50),
      allowNull: false,
      comment: '商品名称'
    },
    poster: {
      type: STRING(200),
      allowNull: false,
      comment: '产品海报'
    },
    type: {
      type: STRING(50),
      allowNull: false,
      comment: '产品类型'
    },
    gitee_url: {
      type: STRING(200),
      allowNull: false,
      comment: 'gitee地址'
    },
    status: {
      type: INTEGER(4),
      allowNull: false,
      defaultValue: 1,
      comment: '状态:1:正常:0:删除'
    },
    created_at: {
      type: DATE,
      get() {
        return new Date(this.getDataValue('created_at')).getTime()
      }
    },
    updated_at: DATE
  })
  Product.associate = function () {
    // 一对一关系
    Product.hasOne(app.model.ProductDetail, {
      foreignKey: 'id'
    })
  }
  return Product
}
